package com.example.wanxiang.service.Impl;

import com.example.wanxiang.entity.Comment;
import com.example.wanxiang.repository.CommentRepository;
import com.example.wanxiang.service.CommentService;
import jakarta.annotation.Resource;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {
    @Resource
    private CommentRepository commentRepository;

    @Override
    public List<Comment> findByArticleId(String articleId, Pageable pageable) {
        return commentRepository.findByArticleId(articleId, pageable);
    }

    @Override
    public Comment findById(String id) {
        return commentRepository.findById(id).orElse(null);
    }

    @Override
    public Comment save(Comment comment) {
        return commentRepository.save(comment);
    }

    @Override
    public void deleteById(String id) {
        commentRepository.deleteById(id);
    }

    @Override
    public List<Comment> findByParentId(Long parentId) {
        return commentRepository.findByUserId(parentId);
    }

}
